package com.tanhua.server.controller;

import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 查看评论列表
     * GET/comments
     */
    @GetMapping
    public ResponseEntity findCommentList(String movementId,
                                          @RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pagesize) {
        return commentService.findCommentList(movementId, page, pagesize);
    }

    /**
     * 文字评论提交
     * POST/comments
     */
    @PostMapping
    public ResponseEntity commitComment(@RequestBody Map map) {
        String publishId = (String) map.get("movementId");
        String content = (String) map.get("comment");
        return commentService.saveComment(publishId, content);
    }

}
